<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .container {
        width: 600px;
        height: 350px;
        border: 1px solid #000;
        overflow: auto;
      }
    </style>
  </head>

  <body>
    <div class="container"></div>
    <button id="btn1">建立连接</button>
    <input type="text" id="txt" />
    <button id="btn2">发送消息</button>
    <button id="btn3">关闭连接</button>

    <script>
      // 找到输入框
      const txt = document.querySelector("#txt");
      // 找到容器
      const container = document.querySelector(".container");

      document.querySelector("#btn1").onclick = function () {
        let ws = new WebSocket("ws://zllhyy.cn:4430");
        ws.addEventListener("open", function () {
          console.log("建立链接了");
        });
        
      };
    </script>
  </body>
</html>
